/* Convenience wrapper for coordinates, etc. */

#ifndef MC_VECTOR2_HPP
#define MC_VECTOR2_HPP

#include <cmath>

namespace memchart
{
	struct vector2
	{
		double x, y;

		vector2 ()
			: x(0), y(0)
		{ }

		vector2 (double x, double y)
			: x(x), y(y)
		{ }

		vector2 & normalize ()
		{
			double len = length();
			x /= len; y /= len;
			return *this;
		}

		double length () const
		{
			return std::sqrt(length2());
		}

		double length2 () const
		{
			return x * x + y * y;
		}

		vector2 operator + (const vector2 & other) const
		{
			return vector2(x + other.x, y + other.y);
		}

		vector2 operator - (const vector2 & other) const
		{
			return vector2(x - other.x, y - other.y);
		}

		vector2 operator * (double d) const
		{
			return vector2(x * d, y * d);
		}

		vector2 operator / (double d) const
		{
			return vector2(x / d, y / d);
		}

		vector2 & operator += (const vector2 & other)
		{
			x += other.x; y += other.y;
			return *this;
		}

		vector2 & operator -= (const vector2 & other)
		{
			x -= other.x; y -= other.y;
			return *this;
		}

		vector2 & operator *= (double d)
		{
			x *= d; y *= d;
			return *this;
		}

		vector2 & operator /= (double d)
		{
			x /= d; y /= d;
			return *this;
		}
	};
}

#endif /* MC_VECTOR2_HPP */
